<?php

class Application_Model_GeneralizeGift extends Application_Model_DomainObject {

    protected $_id;
    /**
     * 礼物名称
     */
    protected $_name;
    /**
     * 礼物简介
     */
    protected $_content;
    /**
     * 礼物类型
     */
    protected $_type;
    /**
     * 礼物重量或优惠券底线
     */
    protected $_weightOrMoney;
    /**
     * 礼物体积或优惠券折扣
     */
    protected $_volumeOrDiscount;
    /**
     * 礼物类型或优惠券有效期
     */
    protected $_typeOrOutTime;
    /**
     * 礼物名称或优惠券批次
     */
    protected $_nameOrBatchNo;
    /**
     * 礼物图片或优惠券名称
     */
    protected $_imgOrBatchName;
    /**
     * 优惠券使用范围
     */
    protected $_scope;
    /**
     * 创建时间
     */
    protected $_dateCreated;
    /**
     * 添加人
     */
    protected $_operator;
    /**
     * 礼物为优惠券
     */
    const Type_Coupon = 1;
    /**
     * 礼物为实体物品
     */
    const Type_Store = 2;
       
    public static function getTypeAll()
    {
        return array(
                   self::Type_Coupon => "优惠券"
                ,  self::Type_Store => "实体礼物"
        );
    }
    
    public function getTypeName()
    {
        $arrType = self::getTypeAll();
        return $arrType[$this->_type];
    }

    public static function getFilter($giftSearch,$pagesize,$pageindex)
    {
        return self::getDao()->queryPage($giftSearch->getSearchFileds(), " id desc ", $pagesize, $pageindex);
    }
    
    public static function getGiftAll($giftSearch)
    {
        return self::getDao()->queryAll($giftSearch->getSearchFileds());
    }
    /**
     * 添加活动礼物
     * @param type $name 礼物名称
     * @param type $content 礼物简介
     * @param type $type 礼物类型
     * @param type $weightOrMoney 物品重量或优惠券底线
     * @param type $volumeOrDiscount 物品体积或优惠券折扣
     * @param type $typeOrOutTime 物品类型或优惠券有效天数
     * @param type $nameOrBatchNo 物品名称或优惠券批次
     * @param type $imgOrBatchName 物品图片或优惠券名称
     * @param type $scope 优惠券使用范围
     * @param type $operator 添加人
     */
    public static function addGift($name,$content,$type,$weightOrMoney,$volumeOrDiscount,$typeOrOutTime,$nameOrBatchNo,$imgOrBatchName,$scope,$operator)
    {
        $giftItem = new Application_Model_GeneralizeGift();
        $giftItem->Name = $name;
        $giftItem->Content = $content;
        $giftItem->Type = $type;
        $giftItem->WeightOrMoney = $weightOrMoney;
        $giftItem->TypeOrOutTime = $typeOrOutTime;
        $giftItem->NameOrBatchNo = $nameOrBatchNo;
        $giftItem->VolumeOrDiscount = $volumeOrDiscount;
        $giftItem->ImgOrBatchName = $imgOrBatchName;
        $giftItem->Scope = $scope;
        $giftItem->Operator = $operator;
        $giftItem->dateCreated = date("Y-m-d H:i:s");
        $giftItem->save();
    }
    
    public function getScopeName()
    {
        $arrScope = Application_Model_Coupon::getbyscope();
        return $arrScope[$this->_scope];
    }
    
    public function getItemTypeName() {
        $names = Application_Model_StoreItem::getNames();
        if ($this->_typeOrOutTime == 0) {
            return $names['0'][0];
        }
        $nameAll = '';
        if ($this->_typeOrOutTime) {
            foreach ($names as $key => $name) {
                if (($this->_typeOrOutTime & $key) == $key) {
                    $nameAll = $nameAll . $name[0] . '/';
                }
            }
        }
        return $nameAll;
    }
}
